//package com.weather.config;
//
//import com.weather.common.utils.http.HttpUtils;
//import net.i2p.crypto.eddsa.EdDSAEngine;
//import net.i2p.crypto.eddsa.EdDSAPrivateKey;
//import net.i2p.crypto.eddsa.spec.EdDSANamedCurveTable;
//import net.i2p.crypto.eddsa.spec.EdDSAParameterSpec;
//import org.springframework.boot.CommandLineRunner;
//import org.springframework.stereotype.Component;
//
//import java.nio.charset.StandardCharsets;
//import java.security.MessageDigest;
//import java.security.PrivateKey;
//import java.security.Signature;
//import java.security.spec.PKCS8EncodedKeySpec;
//import java.time.ZoneOffset;
//import java.time.ZonedDateTime;
//import java.util.Base64;
//@Component
//public class Qweather implements CommandLineRunner {
//
//    private String Qweather_TOKEN;
//
//    public String getQweather_TOKEN() {
//        return Qweather_TOKEN;
//    }
//
//    @Override
//    public void run(String... args) throws Exception {
//        // Private key
//        String privateKeyString = "YOUR PRIVATE KEY";
//        privateKeyString = privateKeyString.trim().replace("-----BEGIN PRIVATE KEY-----", "").replace("-----END PRIVATE KEY-----", "").trim();
//        byte[] privateKeyBytes = Base64.getDecoder().decode(privateKeyString);
//        PKCS8EncodedKeySpec encoded = new PKCS8EncodedKeySpec(privateKeyBytes);
//        PrivateKey privateKey = new EdDSAPrivateKey(encoded);
//
//        // Header
//        String headerJson = "{\"alg\": \"EdDSA\", \"kid\": \"YOUR_KEY_ID\"}";
//
//        // Payload
//        long iat = ZonedDateTime.now(ZoneOffset.UTC).toEpochSecond() - 30;
//        long exp = iat + 900;
//        String payloadJson = "{\"sub\": \"YOUR_PROJECT_ID\", \"iat\": " + iat + ", \"exp\": " + exp + "}";
//
//        // Base64url header+payload
//        String headerEncoded = Base64.getUrlEncoder().encodeToString(headerJson.getBytes(StandardCharsets.UTF_8));
//        String payloadEncoded = Base64.getUrlEncoder().encodeToString(payloadJson.getBytes(StandardCharsets.UTF_8));
//        String data = headerEncoded + "." + payloadEncoded;
//
//        EdDSAParameterSpec spec = EdDSANamedCurveTable.getByName(EdDSANamedCurveTable.ED_25519);
//
//        // Sign
//        final Signature s = new EdDSAEngine(MessageDigest.getInstance(spec.getHashAlgorithm()));
//        s.initSign(privateKey);
//        s.update(data.getBytes(StandardCharsets.UTF_8));
//        byte[] signature = s.sign();
//
//        String signatureString = Base64.getUrlEncoder().encodeToString(signature);
//
//        System.out.println("Signature: \n" + signatureString);
//
//        // Print Token
//        String jwt = data + "." + signatureString;
//        System.out.println("JWT: \n" + jwt);
//        Qweather_TOKEN = jwt;
//    }
//}
